package cn.itcast.controller.stat;

import cn.itcast.controller.BaseController;
import cn.itcast.service.stat.StatService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/stat")
public class StatController extends BaseController {

    @Reference
    private StatService statService;

    @RequestMapping(value = "/toCharts",name = "进入到统计分析的页面")
    public String toCharts(String chartsType){
        return "stat/stat-"+chartsType;
    }

    @RequestMapping(value = "/factoryCharts",name = "和本企业合作的每个厂家的销售金额统计")
    @ResponseBody
    public List<Map> factoryCharts(){
//      select factory_name as name ,SUM(amount) as value from co_contract_product where company_id='1'  GROUP BY factory_name
        return statService.factoryCharts(getCompanyId());
    }

    @RequestMapping(value = "/sellCharts",name = "完成本企业所售出的每一种产品的销售量的前15名")
    @ResponseBody
    public List<Map> sellCharts(){
//        select product_no as name ,SUM(cnumber) as value from co_contract_product where company_id='1'
//        GROUP BY product_no  ORDER BY value desc limit 15
        return statService.sellCharts(getCompanyId());
    }

    @RequestMapping(value = "/onlineCharts",name = "统计24小时每个小时系统的访问量")
    @ResponseBody
    public List<Map> onlineCharts(){
//        select soi.A1 as name ,IFNULL(t.num,0) as value  from st_online_info soi LEFT JOIN (select DATE_FORMAT(time,'%H') hours ,count(0)
//        num from st_sys_log where company_id='1'  GROUP BY DATE_FORMAT(time,'%H')) t
//        on soi.A1=t.hours
        return statService.onlineCharts(getCompanyId());
    }

}
